package backend_0001;

public class Triangle {
    public double side1,side2,side3;
    public Triangle(double side1,double side2,double side3){
        this.side1=side1;
        this.side2=side2;
        this.side3=side3;
    }
    public String area(){
        try {
            if(side1>0&&side2>0&&side3>0&&(side1+side2)>side3&&(side1+side3)>side2&&(side2+side3)>side1){
                double p=(side1+side3+side2)/2;
                double temp=p*(p-side1)*(p-side2)*(p-side3);
                return String.valueOf(Math.sqrt(temp));
            }
            else {
                throw new NotTriangle("三边无法构成三角形");
            }
        }
        catch (NotTriangle e){
            return e.getMessage();

        }

    }

    public static void main(String[] args) {
        Triangle Trangle1=new Triangle(3.0,4.0,5.0);
        Triangle Trangle2=new Triangle(1.0,1.0,2.0);
        System.out.println("Trangle1的面积："+Trangle1.area());
        System.out.println("Trangle2的面积："+Trangle2.area());

    }

}
